﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpPcap;

namespace StuMana.Services
{
    class NetworkController
    {
        private static NetworkController instance;

        public static NetworkController getInstance()
        {
            if (instance == null)
            {
                instance = new NetworkController();
            }
            return instance;
        }

        public NetworkController()
        {
            // Print SharpPcap version
            string ver = SharpPcap.Version.VersionString;
            Console.WriteLine("SharpPcap {0}, Example3.BasicCap.cs", ver);

        }


        /**
         * Get device list.
         */
        public void getDevices()
        {
            //// Print SharpPcap version 
            //string ver = SharpPcap.Version.VersionString;
            //Console.WriteLine("SharpPcap {0}, Example1.IfList.cs", ver);

            //// Retrieve the device list
            //LivePcapDeviceList devices = LivePcapDeviceList.Instance;

            //// If no devices were found print an error
            //if (devices.Count < 1)
            //{
            //    Console.WriteLine("No devices were found on this machine");
            //    return;
            //}

            //Console.WriteLine("\nThe following devices are available on this machine:");
            //Console.WriteLine("----------------------------------------------------\n");

            //// Print out the available network devices
            //foreach (LivePcapDevice dev in devices)
            //    Console.WriteLine("{0}\n", dev.ToString());

            //Console.Write("Hit 'Enter' to exit...");
            //Console.ReadLine();
            // Retrieve the device list
            var devices = CaptureDeviceList.Instance;

            // If no devices were found print an error
            if (devices.Count < 1)
            {
                Console.WriteLine("No devices were found on this machine");
                return;
            }

            Console.WriteLine();
            Console.WriteLine("The following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine();

            int i = 0;

            // Print out the devices
            foreach (var dev in devices)
            {
                /* Description */
                Console.WriteLine("" + i + " " + dev.Name + dev.Description);
                i++;
            }
        }
    }
}
